package com.www.conversionspring.configs;

import com.www.conversionspring.converters.ComputerMobileConverter;
import com.www.conversionspring.formatters.TranslaterFormatterFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ConversionServiceFactoryBean;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.support.DefaultFormattingConversionService;

import java.util.HashSet;

/**
 * <p>
 * </p>
 *
 * @author Zed.Yun
 * @Title: MyConfiguration
 * @ProjectName conversion-spring
 * @date 2019/3/18 14:06
 */
@Configuration
public class MyConfiguration {
//
//    @Bean
//    public ConversionServiceFactoryBean conversionServiceFactoryBean(){
//        ConversionServiceFactoryBean conversionServiceFactoryBean = new ConversionServiceFactoryBean();
//        HashSet<Converter> set = new HashSet<>();
//        set.add(new ComputerMobileConverter());
//        conversionServiceFactoryBean.setConverters(set);
////        conversionServiceFactoryBean.addFormatterForFieldAnnotation(new TranslaterFormatterFactory());
//        return conversionServiceFactoryBean;
//    }



    @Bean
    public DefaultFormattingConversionService defaultFormattingConversionService(){
        DefaultFormattingConversionService formattingConversionService = new DefaultFormattingConversionService();
        formattingConversionService.addFormatterForFieldAnnotation(new TranslaterFormatterFactory());
        return formattingConversionService;
    }




}
